package com.fanco.learn_datastruct_leetcode.designpattern.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @author qiaowang 2022/2/22
 * 描述
 */
public class OutputImpl {

    // 学院集合
    List<Colleage> colleageList;

    public OutputImpl(List<Colleage> colleageList) {
        this.colleageList = colleageList;
    }

    // 遍历所有学院，然后调用PrintDepartment 输出各个学院的系
    public void printCollege () {
        // 从这个collegeList 取出所有学院
        Iterator<Colleage> iterator = colleageList.iterator();
        while (iterator.hasNext()) {
            Colleage colleage = iterator.next();
            System.out.println("=========" + colleage.getName() + "=============");
            Iterator iterator1 = colleage.createIterator();
            printDepartment(iterator1);
        }
    }

    public void printDepartment (Iterator iterator) {
        while (iterator.hasNext()) {
            Department next = (Department) iterator.next();
            System.out.println(next.getName());

        }
    }
}

